define(function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        var _this = this;
        return {
          formdata: {},
          urls: {
            index: backend.workflowService + '/api/monitor/his',
            activate: backend.workflowService + '/api/core/activate'
          },
          tableColumns: [
            { label: '流程实例号', prop: 'instanceId', resizable: true},
            { label: '业务流水号', prop: 'bizId', resizable: true, hidden: false},
            { label: '流程名称', prop: 'flowName', resizable: true},
            { label: '流程编号', prop: 'flowId', resizable: true, hidden: false, width: 60},
            { label: '发起人', prop: 'flowStarterName', resizable: true, hidden: false},
            { label: '客户编号', prop: 'bizUserId', resizable: true, hidden: true},
            { label: '客户名称', prop: 'bizUserName', resizable: true, hidden: true},
            {
              label: '流程状态',
              prop: 'flowState',
              width: 100,
              resizable: true,
              hidden: false,
              template: function () {
                return '<template scope="scope">\
                <yu-tag type="success" v-if="scope.row.flowState==\'E\'">正常结束</yu-tag>\
                <yu-tag type="danger" v-if="scope.row.flowState==\'F\'">否决</yu-tag>\
                <yu-tag type="warning" v-if="scope.row.flowState==\'H\'">挂起</yu-tag>\
                <yu-tag type="primary" v-if="scope.row.flowState==\'P\'">暂停</yu-tag>\
                <yu-tag type="success" v-if="scope.row.flowState==\'R\'">运行中</yu-tag>\
                <yu-tag type="gray" v-if="scope.row.flowState==\'S\'">待发起</yu-tag>\
                </template>';
              }
              
            },
            { label: '开始时间', prop: 'startTime', resizable: true, hidden: false},
            { label: '结束时间', prop: 'endTime', resizable: true, hidden: false},
            { label: '系统编号', prop: 'systemId', resizable: true, hidden: true},
            { label: '业务类型', prop: 'bizType', resizable: true, hidden: false},
            { label: '管理员机构id', prop: 'orgId', resizable: true, hidden: true},
            {
              label: '操作',
              width: 180,
              fixed: 'right',
              template: function () {
                return '<template scope="scope">\
                <el-button size="small" type="text" @click="$emit(\'custom-row-op\',scope,\'DETAIL\')">详情</el-button>\
                <el-button size="small" type="text" @click="$emit(\'custom-row-op\',scope,\'TRACK\')">流程轨迹</el-button>\
                <el-button size="small" type="text" @click="$emit(\'custom-row-op\',scope,\'ACTIVATE\')">激活</el-button>\
                </template>';
              }
            }

          ],
          baseParams: { condition: JSON.stringify() },
          height: yufp.frame.size().height - 103,
          trackDialogVisible: false,
          tracktitle: '流程轨迹',
          nwfTrackPage: 'nwfTrackPage'
        };
      },
      methods: {
        customRowOp: function (scope, op) { // 表格操作按钮事件
          var _this = this;
          // 当前行号：scope.$index 当前行数据：scope.row 当前列对象：scope.column
          // this.$alert('你现在正在操作：' + op + '当前行ID值为：' + scope.row.flowId, '提示');
          // console.log(scope.row.flowId);
          var param = {
            instanceId: scope.row.instanceId,
            bizParam: scope.row,
            flowId: scope.row.flowId,
            type: 'HIS',
            returnBackFuncId: cite.id,
            returnBackRootId: cite.rootId
          };
          if (op == 'DETAIL') {
            yufp.router.to('runInstanceInfo', param, cite.rootId);
          } else if (op == 'ACTIVATE') {
            _this.activateFn(scope.row.instanceId);
          } else if (op == 'TRACK') {
            _this.trackDialogVisible = true;
            var flowId = scope.row.flowId;
            var routeId = 'router_flow_' + flowId;
            var url = 'pages/workflow/studio/wfmonitor/workTravel/workTravel';
            // 判断路由是否已经存在
            var r = yufp.router.getRoute(routeId);
            if (!r || !r.html) {
              yufp.router.addRoute(routeId, {
                html: url + '.html',
                js: url + '.js'
              });
            }
            _this.$nextTick(function () {
              try {
                yufp.router.to(routeId, param, _this.nwfTrackPage);
              } catch (e) { }
            });
          }
        },
        // 将已结束的-否决的流程激活重新办理
        activateFn: function (instanceId) {
          var _this = this;
          _this.$confirm('确定要执行激活操作吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(function () {
            var param = {
              instanceId: instanceId,
              currentUserId: yufp.session.userCode
            };
            yufp.service.request({
              method: 'GET',
              data: param,
              url: _this.urls.activate,
              callback: function (code, message, response) {
                if (response.code == 0) { // 跳转到之前的页面
                  _this.$refs.reftable.remoteData();
                  _this.$message({ message: response.data.tip + ';', type: 'success', duration: 4000 });
                  yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
                } else {
                  _this.$message({ message: response.message + ';', type: 'error', duration: 4000 });
                }
              }
            });
          }).catch(function (e) { });
        }
      }
    });
  };
});
